<?php include incTemplate('header');?>
<script type="text/javascript">
$(function(){
	$('#messagelist').datagrid({
		title:'留言列表',
		nowrap: false,
		url:'/admin.php/message/messagelist',
		remoteSort: true,
		rownumbers:true,
		pagination:true,
		singleSelect:true,
	    columns:[[  
	              {field:'title',title:'留言标题',width:250},
/*
	              ,  
	              {field:'hasreply',title:'是否回复',width:100,formatter:function(val,rowdata,rowindex){
	            	  if(rowdata.hasreply == 1){
							return "<span class='red'>是</span>";
		              }else{
		            	  return "<span>否</span>";
			          }
		           }
		          },  
*/
		          
	              {field:'createtime',title:'发布时间',width:180}
	    ]],
	    onDblClickRow:function(rowIndex, rowData ){
	   
	    	var sr = rowData;
			$("#msg_title").html(sr.title);
			$("#msg_content").html(sr.content);
			$("#msg_faceimg").html("<img src=\'<?php echo HH;?>template/default/images/face/"+sr.faceimg+"\'/>");
			$("#msg_leaver").html(sr.leaver);
			$("#msg_sex").html(sr.sex);
			$("#msg_phonenum").html(sr.phonenumber);
			$("#msg_compname").html(sr.compname);
			$("#msg_address").html(sr.inwhere);
			$("#msg_compaddr").html(sr.address);
	
			$("#win_seemsg").window({  
				title:sr.title,
		        modal:true,
		        width:600,
		        draggable:false,
		        minimizable:false,
		        maximizable:false,
		        collapsible:false,
		        resizable:false
		    });  
	    
	    },
	    toolbar:[
	     	    /*
	     	    {
			id:'btnedit',
			text:'修改',
			iconCls:'icon-edit',
			handler:function(){
	    		var sr = $('#messagelist').datagrid("getSelected");
				if(sr){
					$("#up_msgid").val(sr.id);
					$("#up_msgtitle").val(sr.title);

					//设置tinymce的默认值
					$("#up_content").val(sr.content);
					
					$('#win_updatemsg').window({  
				        modal:true,
				        width:500,
				        draggable:false,
				        minimizable:false,
				        maximizable:false,
				        collapsible:false,
				        resizable:false
				    });  
				}else{
					$.messager.alert('提示','请选择留言！');
				}
			}
		},'-',
*/
			{
				id:'btn_see',
				text:'查看',
				handler:function(){
					var sr = $('#messagelist').datagrid("getSelected");
					if(sr){
						$("#msg_title").html(sr.title);
						$("#msg_content").html(sr.content);
						$("#msg_faceimg").html("<img src=\'<?php echo HH;?>template/default/images/face/"+sr.faceimg+"\'/>");
						$("#msg_leaver").html(sr.leaver);
						$("#msg_sex").html(sr.sex);
						$("#msg_phonenum").html(sr.phonenumber);
						$("#msg_compname").html(sr.compname);
						$("#msg_address").html(sr.inwhere);
						$("#msg_compaddr").html(sr.address);

						$("#win_seemsg").window({  
							title:sr.title,
					        modal:true,
					        width:600,
					        draggable:false,
					        minimizable:false,
					        maximizable:false,
					        collapsible:false,
					        resizable:false
					    });  
						
					}else{
						$.messager.alert('提示','请选择留言！');
					}
				}
			},'-',{
			id:'btndelete',
			text:'删除',
			iconCls:'icon-cut',
			handler:function(){
				var sr = $('#messagelist').datagrid("getSelected");
				if(sr){
					$.post('/admin.php/message/messagedelete',{id:sr.id},function(data){
						if(data.success){
							$.messager.alert('提示','留言删除成功！');
							$('#messagelist').datagrid("reload");
						}else{
							$.messager.alert('提示','留言删除失败！');
						}
					},'json');
				}else{
					$.messager.alert('提示','请选择留言！');
				}
			
			}
		}
/*
		,'-',{
			id:'btnadd',
			text:'回复',
			iconCls:'icon-add',
			handler:function(){
				var sr = $('#messagelist').datagrid("getSelected");
				if(sr){
					$("#win_reply").window({  
				        modal:true,
				        width:500,
				        draggable:false,
				        minimizable:false,
				        maximizable:false,
				        collapsible:false,
				        resizable:false
				    });  

				    $("#msgtitle").html(sr.title);
				    $("#reply").val(sr.reply);
				}else{
					$.messager.alert('提示','请选择留言！');
				}
			}
		}
*/
		]
	    
	});
});
function updateMsg(){
	var title = $("#up_msgtitle").val();
	if(title == "" && title == null){
		$.messager.alert('提示','标题不能为空！'); 
		return;
	}
	
	var content =$("#up_content").val();
	if(content.length<20){
		$.messager.alert('提示','内容不能少于20个字符！'); 
		return;
	}

	var param = {
			id:$("#up_msgid").val(),
			title:$("#up_msgtitle").val(),
			content:$("#up_content").val()
			
	};
	$.post('/admin.php/message/messageupdate',param,function(data){
			if(data.success){
				$.messager.alert('提示',data.message);
				$('#win_updatemsg').window("close");
				clearmsgupdte();
				$('#messagelist').datagrid("reload");
			}else{
				$.messager.alert('提示','留言修改失败！');
			}
	},'json');
}
function addReply(){
	var reply = $("#reply").val();
	var msid = $('#messagelist').datagrid("getSelected").id;

	var param = {mid:msid,rep:reply};
	$.post('/admin.php/message/addreply',param,function(data){
		if(data.success){
			$.messager.alert('提示',data.message);
		}else{
			$.messager.alert('提示','留言编辑失败！');
		}
	},'json');
}
function clearmsgupdte(){
	$("#up_msgid").val("");
	$("#title").val("");
	$("#content").val("");
}

</script>
</head>
<body class="body">
<div class="hidden">
<div id="win_updatemsg" title="修改留言"><input type="hidden" id="up_msgid"
	name="up_msgid" />
<table class="tab_form">
	<tr>
		<td>标题：<input type="text" name="up_msgtitle"
			class="easyui-validatebox w_250" required="true" id="up_msgtitle" /></td>
	</tr>
	<tr>
		<td colspan="2"><textarea name="up_content" id="up_content"
			style="width: 99%; height: 200px;"></textarea></td>
	</tr>
	<tr>
		<td><input onclick="updateMsg()" type="button" value="编辑" /></td>
	</tr>

</table>
</div>

<div id="win_reply" title="回复留言">
<table class="tab_form">
	<tr>
		<td>留言标题：<span id="msgtitle"></span></td>
	</tr>
	<tr>
		<td><textarea name="reply" id="reply"
			style="width: 99%; height: 200px;"></textarea></td>
	</tr>
	<tr>
		<td><input onclick="addReply()" type="button" value="回复" /></td>
	</tr>
</table>
</div>

<div id="win_seemsg" title="">
<table class="tab_form">
	<tr>
		<td>标题：<span id="msg_title"></span></td>
	</tr>
	<tr>
		<td>内容：<span id="msg_content"></span></td>
	</tr>
	<tr>
		<td>表情：<span id="msg_faceimg"></span></td>
	</tr>
	<tr>
		<td>留言人：<span id="msg_leaver"></span></td>
	</tr>
	<tr>
		<td>性别：<span id="msg_sex"></span></td>
	</tr>
	<tr>
		<td>手机号码：<span id="msg_phonenum"></span></td>
	</tr>
	<tr>
		<td>公司名称：<span id="msg_compname"></span></td>
	</tr>
	<tr>
		<td>所在地方：<span id="msg_address"></span></td>
	</tr>
	<tr>
		<td>公司地址：<span id="msg_compaddr"></span></td>
	</tr>
</table>
</div>


</div>
<table id="messagelist"></table>
</body>
</html>
